﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MapControlSample
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            InitPage();
        }

        private void InitPage()
        {
            
            Color colorBlue = new Color();
            colorBlue.B = 50;

            
            Color colorGrey = new Color();
            colorGrey.B = 70;
            colorGrey.G = 70;
            colorGrey.R = 70;
            colorGrey.A = 255;

            Color colorPaleYellow = new Color();
            colorPaleYellow.B = 132;
            colorPaleYellow.G = 231;
            colorPaleYellow.R = 239;
            colorPaleYellow.A = 255;


            //Instantiate Map Control and add it to our canvas
            USMapControl map = new USMapControl();
            LayoutRoot.Children.Add(map);
            Canvas.SetLeft(map, 100);
            Canvas.SetTop(map, -20);

            //Assign the properties of the Map Control
            map.States = GetStates();
            map.HeatColor = colorBlue;
            map.RollOverColor = colorPaleYellow;
            map.Update();
        }


        //Get a list of states and assigns them random values
        //The "State" class is defined in the USMapControl
        private List<State> GetStates()
        {
            int lowerValueOfRand = 12000;
            int upperValueOfRand = 54000;

            List<State> StateList = new List<State>();
            string states = "AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY";
            string[] statesArr = states.Split(',');

            Random random = new Random();
            for (int i = 0; i <= statesArr.GetUpperBound(0); i++)
            {
                double stateValue = random.Next(lowerValueOfRand, upperValueOfRand);
                stateValue = stateValue / 100;
                State thisState = new State(statesArr[i], stateValue);
                StateList.Add(thisState);

            }
            return StateList;
        }
    }
}
